package com.example.yyy

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.viewpager.widget.ViewPager
import kotlinx.android.synthetic.main.activity_view_pager.*

class ViewPagerActivity : AppCompatActivity(),ViewPager.OnPageChangeListener,
    SwipeRefreshLayout.OnRefreshListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_pager)
        val goods1 =GoodsInfo(R.drawable.tp,"图片一")
        val goods2 =GoodsInfo(R.drawable.tp,"图片二")
        val goods3 =GoodsInfo(R.drawable.tp,"图片三")
        val imgList = mutableListOf<GoodsInfo>()
        imgList.add(goods1)
        imgList.add(goods2)
        imgList.add(goods3)
        tab_vp_title.setupWithViewPager(vp_vp_content)
        //第几个页面
        vp_vp_content.currentItem = 0
        //下拉刷新监听器
        srl_vp_color.setOnRefreshListener(this)
        //刷新时样式
        srl_vp_color.setColorSchemeColors(Color.RED,Color.YELLOW,Color.GREEN,Color.BLUE)

        vp_vp_content.adapter = ViewPagerAdapter(this,imgList)

    }

    override fun onPageScrollStateChanged(state: Int) {
        TODO("Not yet implemented")
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
        TODO("Not yet implemented")
    }

    override fun onPageSelected(position: Int) {
        TODO("Not yet implemented")
    }

    //刷新事务处理
    override fun onRefresh() {
        srl_vp_color.isRefreshing=false
    }

}